const http = require('http');
const fs = require('fs');
const path = require('path');
var dirPath = __dirname;

http.createServer((req,res)=>{
    res.writeHead(200,{'content-type':'text/html;charset=utf-8'}); 
    if(process.argv[2]){
        fs.readdir(dirPath,(err)=>{
            if(err){
                res.end(err.toString('utf-8'));
            }else{
                var filePath = path.join(__dirname,'/'+process.argv[2]);
                var readable = fs.createReadStream(filePath);
                readable.pipe(res);
            }
        })
    }else{
        var filePath = path.join(__dirname,'/fileReader3.js')
        var readable = fs.createReadStream(filePath);
        readable.pipe(res);
    }
}).listen(8081)
console.log('正在监听8081端口');